//
//  UIBarButtonItem+Extensions.swift
//  郑好微博
//
//  Created by WF on 2017/6/6.
//  Copyright © 2017年 WF. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认 16
    ///   - target: target
    ///   - action: action 
    ///   - isBackButton: 是否是返回按钮，如果是加上箭头
    /// 
    ///   - returns: UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBackButton: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)

        if isBackButton {
            let imageName = "navigationbar_back"
            
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
